home *** CD-ROM | disk | FTP | other *** search
/ Amiga Plus Special 25 / AMIGAplus Sonderheft 25 (2000)(Falke)(DE)(Track 1 of 4)[!].iso / PublicDomain / Anwendungen / DefIcons44 / Processfile.rexx < prev   
OS/2 REXX Batch file  |  2000-01-03  |  6KB  |  201 lines

  1. /* $VER: ProcessFile.rexx 0.23 (03.01.00) 
  2.  * process a file according to the extension */
  3. /* Authors Osma Ahvenlampi, Michael Van Elst, Dan Murrell Jr. 
  4.  * Modified by Eric Sauvageau
  5.  * View a file after de-archiving enhancement by Alejandro Garza */
  6. /* Modified by Stephan Rupprecht for html documents
  7.  * launches browser via OpenURL(.library) */
  8.  
  9. /* This is the program used to view the file if no match is found */
  10. file.default = "SYS:Utilities/MultiView"
  11.  
  12. /* If this is set to 1, the user will be asked whether he wants to delete
  13.  * the file after it has been processed */
  14. file.delete = 0
  15.  
  16. /* If this is set to 1, the user will be prompted if he/she wants to view
  17.  * any of the files in the archive after unpacking */
  18. file.arcview = 1
  19.  
  20. /* list of supported archivers */
  21. file.archive = "LHA LZH LZX"
  22.  
  23. /* where you would like the archive unpacked by default */
  24. file.unpackdir = "ram:"
  25.  
  26. /* full paths to known (un)packers */
  27. archiver.lha = "c:LhA"
  28. archiver.lzx = "c:Lzx"
  29.  
  30. file.html = "HTM HTML"
  31.  
  32. /* next is the list of extensions and the programs used to show them
  33.  * list the extensions in upper case */
  34. file.1.type = "ILBM HAM GIF JPG JPEG"
  35. file.1.viewer = "Multiview >NIL:"
  36. file.2.type = "WAV AU 8SVX"
  37. file.2.viewer = "Play16 >NIL:" /* LOTS better than OPlay... */
  38. file.3.type = "GUIDE TXT DOC"
  39. file.3.viewer = "SYS:Utilities/MultiView >NIL:"
  40. file.4.type = "MPG MPEG"
  41. file.4.viewer = "mp -dither gray8"
  42. file.4.type = "MOV"
  43. file.4.viewer = "qt HAM8 every=1"
  44.  
  45. /* this is the number of the last type */
  46. file.num = 5
  47.  
  48. /* get filename */
  49. parse arg '"' completename '"' '"' pubscreen '"'
  50.  
  51. if completename="" then
  52.     parse arg completename
  53.  
  54. if ~exists(completename) then exit
  55.  
  56. if pubscreen="" then
  57.     pubscreen = "Workbench"
  58.  
  59. viewed = 0
  60. processed = 0
  61.  
  62. if ~show(l, 'rexxsupport.library') then do
  63.     if ~addlib('rexxsupport.library', 0, -30) then do
  64.         address command 'C:RequestChoice PUBSCREEN="'pubscreen'" TITLE="Process File Error" BODY="Could not execute macro*nlibs:rexxsupport.library not found" GADGETS="OK" >NIL:'
  65.         exit 10
  66.     end
  67. end
  68.  
  69. call CheckExt
  70.  
  71. /* test it against known archivers/packers */
  72. if (extension ~= "") & (find( file.archive, extension ) > 0) then do
  73.     viewed = 1
  74.     call UnPack
  75. end
  76.  
  77. if (extension ~= "") & (find( file.html, extension ) > 0) then do
  78.     viewed = 1
  79.     call OpenURL
  80. end
  81.  
  82. /* test it against known file types */
  83. if ~viewed & (extension ~= "") then
  84.     do i = 1 to file.num while ~viewed
  85.         if find( file.i.type, extension ) > 0 then do
  86.             viewed = 1
  87.             address command file.i.viewer '"'completename'"'
  88.             if rc = 0 then
  89.                 processed = 1
  90.  
  91.                 end
  92.     end
  93.  
  94. exit
  95.  
  96. UnPack:
  97.     if (extension = "LHA") | (extension = "LZH") then do
  98.         address command 'C:RequestChoice PUBSCREEN="'pubscreen'" TITLE="Process File" BODY="View archive?" GADGETS="Yes|No" >T:reqchoice.arcview'
  99.  
  100.         call open(choicefile, 'T:reqchoice.arcview', 'R')
  101.         answer = readln(choicefile)
  102.         call close(choicefile)
  103.         address command 'C:Delete >NIL: T:reqchoice.arcview'
  104.  
  105.         if answer = '1' then do
  106.  
  107.                 address command 'LhA  v "'completename'" '
  108.  
  109.                 end
  110.         address command 'C:RequestChoice PUBSCREEN="'pubscreen'" TITLE="Process File" BODY="Un-LHA file 'completename'?" GADGETS="Yes|No" >T:reqchoice.unlha'
  111.     
  112.         call open(choicefile, 'T:reqchoice.unlha', 'R')
  113.         answer = readch(choicefile, 1)
  114.         call close(choicefile)
  115.         address command 'C:Delete >NIL: T:reqchoice.unlha'
  116.  
  117.         if answer = '1' then do
  118.             address command 'C:RequestFile SAVEMODE DRAWER="'file.unpackdir'" TITLE="Choose destination directory" NOICONS DRAWERSONLY PUBSCREEN="'pubscreen'" >T:req.drawer'
  119.  
  120.             call open(choicefile, 'T:req.drawer', 'R')
  121.             file.unpackdir = readln(choicefile)
  122.             call close(choicefile)
  123.             address command 'C:Delete >NIL: T:req.drawer'
  124.     
  125.             if length(answer) > 0 then do
  126.                 address command archiver.lha 'x "'completename'" 'file.unpackdir
  127.                 processed = 1
  128.             end
  129.         end
  130.  
  131.                 return
  132.  
  133.     end
  134.  
  135.  
  136.     if (extension = "LZX") then do
  137.         address command 'C:RequestChoice PUBSCREEN="'pubscreen'" TITLE="Process File" BODY="View archive?" GADGETS="Yes|No" >T:reqchoice.arcview'
  138.  
  139.         call open(choicefile, 'T:reqchoice.arcview', 'R')
  140.         answer = readln(choicefile)
  141.         call close(choicefile)
  142.         address command 'C:Delete >NIL: T:reqchoice.arcview'
  143.  
  144.         if answer = '1' then do
  145.  
  146.                 address command 'Lzx v "'completename'" >T:LhaContents.tmp'
  147.                 address command file.default 'T:LhaContents.tmp'
  148.                 address command 'C:Delete >NIL: T:LhaContents.tmp'
  149.                 end
  150.         address command 'C:RequestChoice PUBSCREEN="'pubscreen'" TITLE="Process File" BODY="Un-LZXfile 'completename'?" GADGETS="Yes|No" >T:reqchoice.unlha'
  151.     
  152.         call open(choicefile, 'T:reqchoice.unlha', 'R')
  153.         answer = readch(choicefile, 1)
  154.         call close(choicefile)
  155.         address command 'C:Delete >NIL: T:reqchoice.unlha'
  156.  
  157.         if answer = '1' then do
  158.             address command 'C:RequestFile SAVEMODE DRAWER="'file.unpackdir'" TITLE="Choose destination directory" NOICONS DRAWERSONLY PUBSCREEN="'pubscreen'" >T:req.drawer'
  159.  
  160.             call open(choicefile, 'T:req.drawer', 'R')
  161.             file.unpackdir = readln(choicefile)
  162.             call close(choicefile)
  163.             address command 'C:Delete >NIL: T:req.drawer'
  164.     
  165.             if length(answer) > 0 then do
  166.                 address command archiver.lzx 'x "'completename'" 'file.unpackdir
  167.                 processed = 1
  168.             end
  169.         end
  170.     end
  171.  
  172.     
  173.     return
  174.  
  175. CheckExt:
  176.     /* find position of the last period, if any, to set off the file extension */
  177.     dot = lastpos(".", completename)
  178.  
  179.     if (dot > 0) then do
  180.         /* there is an extension.. put it in another variable and make it upper case */
  181.         filename = left(completename, dot-1)
  182.         extension = upper(substr(completename, dot+1))
  183.     end
  184.     else do
  185.         filename = completename
  186.         extension = ""
  187.     end
  188.  
  189.     return
  190.  
  191. OpenURL:
  192.     call pragma('D','')
  193.     
  194.     if( length( result ) > lastpos( ':', result ) ) then do
  195.         completename = insert( '/', completename );
  196.     end
  197.     
  198.     completename = insert( result, completename )
  199.     
  200.     address command 'OpenURL "file://localhost/'completename'"'
  201. return